<!--# layout("/common/layout.html",{"jsBase":"/js/contract/contractInfo/"}){ -->

<style>
    .t1{
        height: 100px;
    }
    .t2{
        height: 100px;
        width: 100px;
    }
</style>


<script id="scriptText" type="text/html">

    {{# if( d.textContent == null || d.textContent == undefined
    || d.textContent.content == null  ){  }}

    {{# }else{ }}
    {{# console.log("进入else") }}
    {{# console.log("打印else： "+d.textContent.content) }}
    {{ d.textContent.content }}
    {{# } }}
</script>
<textarea id="text1" style="height: 200px;">
</textarea>



<script id="scriptbutt" type="text/html">
    {{# if(d.isb){ }}

    <div class="t1">
        <div class="t2">
            <p align="">附件： </p>
            <input id="uploadfile" type="file" name="file"/>

        </div>
    </div>

    <button id="sub" class="layui-btn layui-btn-primary" > 提交 </button>
    <button id="exit" class="layui-btn layui-btn-primary" > 取消 </button>
    {{# }else{  }}

    {{# } }}
</script>
<div id="butt">

</div>

<!--footer-->
<script src=""></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','upload','laytpl','layedit','element'],function () {
        var $ = layui.jquery;
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        var layer = layui.layer;
        var layedit =layui.layedit;
        var upload = layui.upload;
        var  layeditIndex  = layedit.build('text1');

        var fatherParent = window.parent.indexNodeSchedule;//父页面数据
        var fatherserviceNodeMapList = window.parent.processList;//父页面的列表数据


        var thisServicceInfo =  fatherserviceNodeMapList[(fatherParent.trIndex)-1]
        console.dir("thisServicceInfo： ",thisServicceInfo);
        console.dir("fatherParent： ",fatherParent);


        //设置文本内容
        var tplm = scriptText.innerHTML;
        var text1 = document.getElementById('text1');
        laytpl(tplm).render({"textContent":thisServicceInfo},function(html1){
            text1.innerHTML = html1;
        })
        element.init();

        console.log("是否显示提交按钮： "+window.parent.isHiddenButton)
        //判断是否需要显示确定按钮
        var butttplm = scriptbutt.innerHTML;
        var butttext1 = document.getElementById('butt');
        laytpl(butttplm).render({"isb":window.parent.isHiddenButton},function(html1){
            butttext1.innerHTML = html1;
        })


        var upBoolean = false;
        var onlyBoolean = true;//是否上传文件
        //上传文件
        var upOtherData = new Object();
        upOtherData["text"] = layedit.getContent(layeditIndex);
        upOtherData["contractid"] = fatherParent.contractid;
        upOtherData["srviceid"] = fatherParent.srviceid;
        upOtherData["nodeid"] = fatherParent.nodeid;
        upOtherData["invoiceno"] = thisServicceInfo.ainvoiceno;//合同编号，用来生成存放上传文件 的文件夹

        upOtherData["isuploadfile"] =false;

        console.log("正式请求的： "+JSON.stringify(upOtherData))
        var uploadInst = upload.render({
            elem:'#uploadfile'
            ,url:Common.ctxPath+'/contract/createcontract/upload.json'
            ,accept:'file'
            ,bindActi:'#sub'
            ,auto :false//不自动上传
            ,data: JSON.stringify(upOtherData)
            ,choose:function (obj) {
                console.dir(upOtherData);
                obj.preview(function(index, file, result){
                    onlyBoolean = false;
                    if (upBoolean){
                        obj.upload(index, file);//文件上传
                    }
                })
            }
            ,before:function() {//文件上传前

            }
            ,done:function(res){
                window.parent.location.reload()
            }
            ,error:function(){
                alert("上次文件失败")
            }
        })

        //点击重新上传
        $(document).on('click','#sub',function () {
            if (onlyBoolean){//如果没有文件上传
                upOtherData["text"] = layedit.getContent(layeditIndex);
                console.log(JSON.stringify(upOtherData))
                $.ajax({
                    url:Common.ctxPath+'/contract/createcontract/upload.json'
                    ,type:'POST'
                    // ,contentType:'multipart/form-data'
                    ,data:JSON.stringify(upOtherData)
                    ,dataType:'text'
                    ,success:function (data) {
                        window.parent.location.reload()
                    }
                })

            }else{

                upOtherData["text"] = layedit.getContent(layeditIndex);
                console.log("请求前获取的："+JSON.stringify(upOtherData))
                upOtherData["isuploadfile"] =true;
                upBoolean=true;

                uploadInst.reload({
                    data:JSON.stringify(upOtherData)
                });
                uploadInst.upload();
            }

        })

        $(document).on('click','#exit',function () {
            var ht =  window.parent.document;
            window.parent.layer.closeAll();

        })









    })

</script>

<!--#} -->
